{% extends "vmServer/index_server.html" %}

{% block content %}

						<div class="row">
							<div class="col-xs-3 col-sm-3">
							</div>

									<div class="col-xs-6 col-sm-6 widget-container-span">
										<div class="widget-box">
											<div class="widget-header widget-header-large">
												<h4>
													<i class="icon-edit"></i>
													添加存储池
												</h4>

												<div class="widget-toolbar">
													<a href="#" data-action="settings">
														<i class="icon-cog"></i>
													</a>

													<a href="#" data-action="reload">
														<i class="icon-refresh"></i>
													</a>

													<a href="#" data-action="collapse">
														<i class="icon-chevron-up"></i>
													</a>

													<a href="#" data-action="close">
														<i class="icon-remove"></i>
													</a>
												</div>
											</div>

											<div class="widget-body">
												<div class="widget-main">
								<form class="form-horizontal" role="form" id="addStroage">
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1">
											 <strong>
											 	虚拟管理器
											 </strong> 
										</label>

										<div class="col-sm-9">
											<input class="input-sm" type="text"   value="{{ vmServer.server_ip }}" disabled/>	
										</div>
										<div class="col-sm-9" style="display: none;">
											<input class="input-sm" type="text" name="pool_server"   value="{{ vmServer.id }}"/>	
										</div>										
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-input-readonly"><strong> 类型</strong> </label>

										<div class="col-sm-9">
											<select id="pool_type" name="pool_type" onchange="javascript:oBtStorageTypeSelect();">
												<option value="dir">DIR</option>
												<option value="disk">DISK</option>	
												<option value="logical">LOGICAL</option>	
												<option value="nfs">NFS</option>	
												<option value="iscsi">iSCSI</option>	
												<option value="zfs">ZFS</option>
												<option value="gluster">GLUSTER</option>								
											</select>	
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>名称</strong></label>

										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_name" placeholder="Name" value=""/>											
											<div class="space-2"></div>									
										</div>
									</div>
									<div class="form-group" style="display: none;" id="div_pool_host">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>主机地址</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_host" placeholder="host address" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>	
									<div class="form-group" style="display: none;" id="div_pool_logical">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>设备地址</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_spath" placeholder="/dev/sdb1" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>										
									<div class="form-group" style="display: none;" id="div_pool_disk">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>磁盘路径</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_spath" placeholder="/dev/sdb" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>		
									<div class="form-group" style="display: none;" id="div_pool_iscsi">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>ISCSI路径</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_spath" placeholder="iqn.2013-06.com.example:iscsi-pool" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>																		
									<div class="form-group" style="display:none;" id="div_pool_uri">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>URI</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_spath" placeholder="/uri_path/" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>																	
									<div class="form-group" style="display:none;" id="div_pool_spath">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>原路径</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_spath" placeholder="/path/" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>																			
									<div class="form-group" id="div_pool_tpath">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-3"><strong>存储路径</strong></label>
										<div class="col-sm-9">
											<input class="input-sm" type="text" name="pool_tpath" placeholder="/path/" value="" />											
											<div class="space-2"></div>									
										</div>
									</div>									
									<div class="space-4"></div>

									<div class="hr hr32 hr-dotted"></div>
									<div class="form-group">
										<div class="col-md-offset-3 col-md-9">
											<button class="btn btn-info" type="button" onclick="addVmStorage(this)">
												<i class="icon-ok bigger-110"></i>
												提交
											</button>

											&nbsp; &nbsp; &nbsp;
											<button class="btn" type="reset">
												<i class="icon-undo bigger-110"></i>
												撤销
											</button>
										</div>
									</div>						
								</form>
												</div>
											</div>
										</div>
									</div>						
						

						</div><!-- /.row -->

		<script type="text/javascript">

		   function oBtStorageTypeSelect() {
			   var obj = document.getElementById("pool_type"); 
			   var index = obj.selectedIndex;
			   var value = obj.options[index].value; 
			   if (value=="dir"){
				   document.getElementById("div_pool_host").style.display="none";   
				   document.getElementById("div_pool_uri").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="none";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="";
			   }
			   else if (value=="nfs"){
				   document.getElementById("div_pool_host").style.display="";   
				   document.getElementById("div_pool_uri").style.display="";
				   document.getElementById("div_pool_spath").style.display="none";
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="none";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="";
			   }
			   else if (value=="logical"){
				   document.getElementById("div_pool_host").style.display="none";   
				   document.getElementById("div_pool_uri").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";	
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="";
			   }			   
			   else if (value=="disk"){
				   document.getElementById("div_pool_host").style.display="none";   
				   document.getElementById("div_pool_uri").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";	
				   document.getElementById("div_pool_disk").style.display="";
				   document.getElementById("div_pool_logical").style.display="none";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="";
			   }	
			   else if (value=="iscsi"){
				   document.getElementById("div_pool_host").style.display="";   
				   document.getElementById("div_pool_uri").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";	
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="none";
				   document.getElementById("div_pool_iscsi").style.display="";
			   }
			   else if (value=="zfs"){
				   document.getElementById("div_pool_host").style.display="none";   
				   document.getElementById("div_pool_uri").style.display="";
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="none";
			   }			   
			   else if (value=="gluster"){
				   document.getElementById("div_pool_host").style.display="";   
				   document.getElementById("div_pool_uri").style.display="";	
				   document.getElementById("div_pool_disk").style.display="none";
				   document.getElementById("div_pool_logical").style.display="none";
				   document.getElementById("div_pool_iscsi").style.display="none";
				   document.getElementById("div_pool_spath").style.display="none";
				   document.getElementById("div_pool_tpath").style.display="none";
			   }			   
		   }		
		
		   
			function addVmStorage(obj) {
				var server_data = {};
				var form = document.getElementById('addStroage');
				for (var i = 1; i < form.length; ++i) {
					var name = form[i].name;
					var value = form[i].value;
					if ( value.length != 0){
						server_data[name] = value;
					}			
				};
				$.ajax({
					dataType: "JSON",
					url:'/addStorage/', //请求地址
					type:"POST",  //提交类似
					data:server_data,  //提交参数
					success:function(response){
						if (response["code"] == 200){
							window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
						}
						else {
							window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
						}
						
					},
			    	error:function(response){
			    		window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
			    	}
				})	
			}		   
		   
		</script>

{% endblock %}
